package com.itheima.sfbx.insurance.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.SafeguardVO;
import com.itheima.sfbx.insurance.service.ISafeguardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "保障项管理")
@RestController
@RequestMapping("/safeguard")
public class SafeguardController {

    @Resource
    private ISafeguardService safeguardService;


    /**
     * 分页查询 保障项
     * @param safeguardVO 查询条件对象
     * @param pageNum 页号
     * @param pageSize 页大小
     * @return 封装的分页数据
     *
     * @ApiOperation 标记方法的描述信息
     * @ApiImplicitParams 描述接口的形参；每个参数类型、是否必要、参数名称
     * @ApiOperationSupport 描述接口的返回结果
     */
    @ApiOperation(value = "分页查询",notes = "分页查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO"),
        @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
        @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.dataState","safeguardVO.createTime","safeguardVO.updateTime","safeguardVO.createBy","safeguardVO.updateBy","safeguardVO.creator","safeguardVO.remake"})
    @PostMapping("/page/{pageNum}/{pageSize}")
    public ResponseResult<Page<SafeguardVO>> findSafeguardVOPage(@RequestBody SafeguardVO safeguardVO,
                                                                 @PathVariable("pageNum") int pageNum,
                                                                 @PathVariable("pageSize") int pageSize){
        Page<SafeguardVO> page = safeguardService.findPage(safeguardVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(page);
    }

    /**
     * 保障项保存
     * @param safeguardVO 保障项对象
     * @return 保障项对象
     */
    @ApiOperation(value = "保存保障项",notes = "添加保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.tip"})
    @PutMapping
    public ResponseResult<SafeguardVO> createSafeguard(@RequestBody SafeguardVO safeguardVO){
        SafeguardVO vo = safeguardService.save(safeguardVO);
        return ResponseResultBuild.successBuild(vo);
    }

    /**
     * 修改保障项
     * @param safeguardVO 保障项对象
     * @return 修改结果
     */
    @ApiOperation(value = "修改保障项",notes = "修改保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.tip"})
    @PatchMapping
    public ResponseResult<Boolean> updateSafeguard(@RequestBody SafeguardVO safeguardVO){
        Boolean update = safeguardService.update(safeguardVO);
        return ResponseResultBuild.successBuild(update);
    }

    /**
     * 批量删除保障项
     * @param safeguardVO 保障项对象
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除保障项",notes = "批量删除保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.checkedIds"})
    public ResponseResult<Boolean> deleteSafeguard(@RequestBody SafeguardVO safeguardVO){
        Boolean delete = safeguardService.delete(safeguardVO.getCheckedIds());
        return ResponseResultBuild.successBuild(delete);
    }

    /**
     * 查询保障项列表
     * @param safeguardVO 保障项对象
     * @return 列表
     */
    @ApiOperation(value = "查询保障项列表",notes = "查询保障项列表")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.dataState","safeguardVO.sortNo","safeguardVO.safeguardKey","safeguardVO.safeguardKeyName","safeguardVO.safeguardVal","safeguardVO.safeguardType","safeguardVO.tip"})
    @PostMapping("/list")
    public ResponseResult<List<SafeguardVO>> findList(@RequestBody SafeguardVO safeguardVO){
        List<SafeguardVO> list = safeguardService.findList(safeguardVO);
        return ResponseResultBuild.successBuild(list);
    }
}
